package com.project.mapper;

import com.project.bean.EmployeeBean;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;

/**
 * @author lyl
 * description:员工持久层接口
 */
public interface IEmployeeMapper {

    /**
     * 添加员工
     *
     * @param employeeBean 员工对象
     * @param deptId       部门id
     */
    void add(@Param("employeeBean") EmployeeBean employeeBean, @Param("deptId") int deptId);

    /**
     * 根据id删除员工
     *
     * @param employeeId
     */
    @Delete("delete from t_employee where pk_employeeId =#{employeeId}")
    void del(@Param("employeeId") int employeeId);

    /**
     * 按员工id修改员工部门和工资
     *
     * @param employeeId
     * @param deptId
     * @param money
     */
    @Update("update t_employee set fk_deptId = #{deptId},e_money = #{money} where pk_employeeId = #{employeeId}")
    void update(@Param("employeeId") int employeeId, @Param("deptId") int deptId, @Param("money") int money);

    /**
     * 按id查询员工信息同时查询员工所属部门
     *
     * @param employeeId
     * @return 员工对象（包含部门）
     */
    @Select("select t_employee.*,t_dept.d_name deptName from t_employee inner join t_dept on pk_deptId = fk_deptId where pk_employeeId = #{employeeId}")
    @ResultMap("employeeMap")
    EmployeeBean findById(@Param("employeeId") int employeeId);

    /**
     * 按动态条件进行分页查询
     *
     * @param employeeName 员工姓名
     * @param startDate    起始日期
     * @param endDate      结束日期
     * @return 分页对象
     */
    List<EmployeeBean> findByPage(@Param("employeeName") String employeeName, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);


}
